home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Apple Guide / Engineering / APISample / APISampleMPW / TDocument / TDocument.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-29  |  6.1 KB  |  169 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware Simple Application Framework
  6. #
  7. #    TDocument
  8. #
  9. #    TDocument.h        -    C++ source
  10. #
  11. #    Copyright © 1989 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    
  15. #            1.20                    10/91
  16. #            1.10                     07/89
  17. #            1.00                     04/89
  18. #
  19. #    Components:
  20. #            TDocument.h                July 9, 1989
  21. #            TDocument.cp            July 9, 1989
  22. #
  23. ------------------------------------------------------------------------------*/
  24.  
  25. #ifndef TDocument_Defs
  26. #define TDocument_Defs
  27.  
  28. // Include necessary interface files
  29. #include <Types.h>
  30. #include <QuickDraw.h>
  31.  
  32. // Define HiWrd and LoWrd macros for efficiency
  33. #define HiWrd(aLong)    ((short) (((aLong) >> 16) & 0xFFFF))
  34. #define LoWrd(aLong)    ((short) ((aLong) & 0xFFFF))
  35.  
  36. // Define TopLeft and BotRight macros for convenience. Notice the implicit
  37. // dependency on the ordering of fields within a Rect
  38. #define TopLeft(aRect)    (* (Point *) &(aRect).top)
  39. #define BotRight(aRect)    (* (Point *) &(aRect).bottom)
  40.  
  41. const long kMaxSleepTime = 60;    // 1 second worth of ticks
  42.  
  43. /***********************************************************************/
  44. //
  45. //    Class definitions
  46. //
  47. /***********************************************************************/
  48.  
  49.  
  50. //-----------------------------------------------------------------------
  51. // TDocument -    some basic member functions are included. Although it is 
  52. //                not a complete set, it does provide enough functionality
  53. //                to develop subclasses. As you develop subclasses, you may
  54. //                choose to incorporate common functionality of those
  55. //                subclasses into the base class to reduce the complexity
  56. //                of creating others.
  57. //
  58.     class TDocument : public HandleObject    // we derive from handle object to prevent fragmentation
  59.     {
  60.         protected:
  61.             WindowPtr fDocWindow;
  62.         
  63.         public:
  64.             TDocument( short resID );        // our constructor - creates window using resID as template
  65.             virtual ~TDocument();            // our destructor - disposes of window
  66.         
  67.             // you will need to override these in your subclasses,
  68.             // since they are do-nothing routines by default...
  69.                 virtual void DoZoom        ( short            /*partCode*/ )            {}
  70.                 virtual void DoGrow        ( EventRecord*    /*theEvent*/ )            {}
  71.                 virtual void DoContent    ( EventRecord*    /*theEvent*/ )            {}
  72.                 virtual void DoKeyDown    ( EventRecord*    /*theEvent*/ )            {}
  73.                 virtual void DoActivate    ( Boolean        /*becomingActive*/ )    {}
  74.                 virtual void DoUpdate    ( void )                                {}
  75.         
  76.             // file handling routines
  77.                 virtual void DoOpen        ( void )    {};
  78.                 virtual void DoClose    ( void )    { delete this; };    // by default, we just delete ourself & let destructor do cleanup
  79.                 virtual void DoSave        ( void )    {};
  80.                 virtual void DoSaveAs    ( void )    {};
  81.                 virtual void DoRevert    ( void )    {};
  82.                 virtual void DoPrint    ( void )    {};
  83.         
  84.             // do standard edit menu actions
  85.                 virtual void DoUndo        ( void )    {};
  86.                 virtual void DoCut        ( void )    {};
  87.                 virtual void DoCopy        ( void )    {};
  88.                 virtual void DoPaste    ( void )    {};
  89.                 virtual void DoClear    ( void )    {};
  90.                 virtual void DoSelectAll( void )    {};
  91.         
  92.             // idle time routines: you can use these to do cursor handling,
  93.             // TE caret blinking, marquee effects, etc...
  94.                 virtual void DoIdle                ( void )                 {};
  95.                 virtual unsigned long CalcIdle    ( void )                 { return kMaxSleepTime; };    // by default, we don't need idle
  96.                 virtual void AdjustCursor        ( Point /*where*/ )     {};                            // where is in local coords
  97.             
  98.             // query state of document - useful for adjusting menu state
  99.                 virtual Boolean HaveUndo        ( void )    { return false; };
  100.                 virtual Boolean HaveSelection    ( void )    { return false; };
  101.                 virtual Boolean HavePaste        ( void )    { return false; };
  102.                 virtual Boolean CanClose        ( void )    { return true;  };
  103.                 virtual Boolean CanSave            ( void )    { return false; };
  104.                 virtual Boolean CanSaveAs        ( void )    { return true;  };
  105.                 virtual Boolean CanRevert        ( void )    { return false; };
  106.                 virtual Boolean CanPrint        ( void )     { return false; };
  107.         
  108.             // utility routine to get window pointer for document
  109.                 inline WindowPtr GetDocWindow    ( void )     { return fDocWindow; }
  110.                 
  111.     }; /* class TDocument */
  112.  
  113.  
  114. //-----------------------------------------------------------------------
  115. // TDocumentLink -    is a simple utility class which is used by the TDocumentList
  116. //                     class below. You cannot allocate objects of this type yourself,
  117. //                    since its constructor is private. We get around this for
  118. //                    TDocumentList by making it a "friend" of this class. This is
  119. //                    a handy trick.
  120. //
  121.     class TDocumentLink
  122.     {
  123.         friend class TDocumentList;
  124.     
  125.         // class variables
  126.             TDocumentLink*            fNext;            // the link to the next document
  127.             TDocument*                fDoc;            // the document this link refers to
  128.     
  129.         // our constructor. Note that it can take args for convenience,
  130.         // but that they default to nil.
  131.             TDocumentLink( TDocumentLink *n = nil, TDocument *v = nil );
  132.     
  133.         // implementation of our TDocumentLink routines is done inline, for speed
  134.             inline TDocumentLink*    GetNext    ()                             { return fNext;  };
  135.             inline TDocument*         GetDoc    ()                             { return fDoc;   };
  136.             inline void                SetNext    ( TDocumentLink* aLink )     { fNext = aLink; };
  137.             inline void             SetDoc    ( TDocument* aDoc )         { fDoc = aDoc;   };
  138.         
  139.     }; /* class TDocumentLink */
  140.  
  141.  
  142. //-----------------------------------------------------------------------
  143. // TDocumentList -    is a simple linked list of documents, implemented C++ style. I
  144. //                    could have made a general linked list class & just made this a
  145. //                    subclass. This would have been a more general (and more
  146. //                    object-oriented) solution, but I did it from scratch in a
  147. //                    futile attempt at keeping the size of this program at a
  148. //                    reasonable level.
  149. //
  150.     class TDocumentList
  151.     {
  152.         // class variables
  153.             TDocumentLink*    fDocList;    // the first link in our list
  154.             int                fNumDocs;    // the number of elements in the list
  155.         
  156.         public:
  157.             TDocumentList( void );        // our constructor
  158.         
  159.             virtual void        AddDoc        ( TDocument* doc );
  160.             virtual void        RemoveDoc    ( TDocument* doc );
  161.             virtual TDocument*    FindDoc        ( WindowPtr window );        // find the TDocument associated with the window
  162.         
  163.             inline int            NumDocs() { return fNumDocs; }            // return number of active documents
  164.         
  165.     }; /* class TDocumentList */
  166.  
  167.  
  168. #endif TDocument_Defs
  169.